package cn.earas.ip.frame;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.text.DecimalFormat;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

import cn.earas.ip.Data;
import cn.earas.ip.DataUtil;
import cn.earas.ip.Proxy;

public class MainFrame extends JFrame
{
	public boolean scollShowFlag = true;
	public static boolean supper = false;
    public static boolean inFlag;
    public static boolean buttonFlag;
    private static final long serialVersionUID = 1L;
    public static JButton jButton1;
    private JCheckBox jCheckBox3;
    private JCheckBox jCheckBox4;
    private JCheckBox jCheckBox5;
    private JCheckBox jCheckBox1;
    private JComboBox<String> jComboBox1;
    private JFileChooser jFileChooser1;
    private JLabel jLabel1;
    private JLabel jLabel2;
    private JLabel jLabel3;
    private JLabel jLabel4;
    private JMenu jMenu1;
    private JMenu jMenu2;
    private JMenuBar jMenuBar1;
    public static JMenuItem jMenuItem1;
    public static JMenuItem jMenuItem2;
    private JMenuItem jMenuItem3;
    private JMenuItem jMenuItem4;
    private JMenuItem jMenuItem5;
    public static JMenuItem jMenuItem6;
    private JPanel jPanel1;
    private JPanel jPanel2;
    public static JProgressBar jProgressBar1;
    private JScrollPane jScrollPane1;
    private JPopupMenu.Separator jSeparator1;
    public static JTextArea jTextArea1;
    private JTextField jTextField1;
    private javax.swing.JLabel jLabel5;
    public static javax.swing.JToggleButton jToggleButton1;
    public static OutFrame of;
    Icon lock = new ImageIcon(this.getClass().getResource("/images/lock.png"));
//    Icon unlock = new ImageIcon(this.getClass().getResource("/images/unlock.png"));

    int ms = 0;
    int threadNum = 1;

    public MainFrame() {
        this.initComponents();
    }
    
    private void initComponents() {
        this.jFileChooser1 = new JFileChooser();
        this.jPanel1 = new JPanel();
        this.jComboBox1 = new JComboBox<String>();
        this.jTextField1 = new JTextField();
        MainFrame.jButton1 = new JButton();
        MainFrame.jProgressBar1 = new JProgressBar();
        this.jLabel1 = new JLabel();
        this.jCheckBox3 = new JCheckBox();
        this.jCheckBox4 = new JCheckBox();
        this.jCheckBox5 = new JCheckBox();
        this.jLabel2 = new JLabel();
        this.jLabel3 = new JLabel();
        this.jLabel4 = new JLabel();
        jLabel5 = new javax.swing.JLabel();
        jToggleButton1 = new javax.swing.JToggleButton();
        jCheckBox1 = new javax.swing.JCheckBox();
        this.jPanel2 = new JPanel();
        this.jScrollPane1 = new JScrollPane();
        MainFrame.jTextArea1 = new JTextArea();
        this.jMenuBar1 = new JMenuBar();
        this.jMenu1 = new JMenu();
        MainFrame.jMenuItem1 = new JMenuItem();
        MainFrame.jMenuItem2 = new JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        this.jSeparator1 = new JPopupMenu.Separator();
        this.jMenuItem3 = new JMenuItem();
        this.jMenu2 = new JMenu();
        this.jMenuItem4 = new JMenuItem();
        this.jMenuItem5 = new JMenuItem();
        this.setBounds(Toolkit.getDefaultToolkit().getScreenSize().width / 2 - 261, Toolkit.getDefaultToolkit().getScreenSize().height / 2 - 224, 522, 448);
        this.setDefaultCloseOperation(3);
        this.setTitle("\u4ee3\u7406IP\u68c0\u6d4b" + Data.VERSION);
        this.setCursor(new Cursor(0));
        this.setResizable(false);
        this.addWindowListener(new WindowAdapter() {
        	@Override
        	public void windowClosing(WindowEvent e) {
        		if(ProxyFrame.running) Proxy.removeProxy();
        		super.windowClosing(e);
        	}
		});
        final Toolkit tk = Toolkit.getDefaultToolkit();
        final Image imgae = tk.createImage(this.getClass().getResource("/images/logo.png"));
        this.setIconImage(imgae);
        this.jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        this.jComboBox1.setFont(new Font("\u5fae\u8f6f\u96c5\u9ed1", 0, 12));
        this.jComboBox1.setModel(new DefaultComboBoxModel<String>(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }));
        this.jComboBox1.setSelectedIndex(3);
        MainFrame.jButton1.setFont(new Font("\u5fae\u8f6f\u96c5\u9ed1", 0, 12));
        MainFrame.jButton1.setText("\u5f00\u59cb");
        MainFrame.jButton1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent evt) {
                MainFrame.this.jButton1ActionPerformed(evt);
            }
        });
        MainFrame.jProgressBar1.setFont(new Font("\u5fae\u8f6f\u96c5\u9ed1", 0, 12));
        MainFrame.jProgressBar1.setCursor(new Cursor(0));
        MainFrame.jProgressBar1.setEnabled(false);
        MainFrame.jProgressBar1.setForeground(new Color(0, 0, 0));
        MainFrame.jProgressBar1.setStringPainted(true);
        this.jLabel1.setFont(new Font("\u5fae\u8f6f\u96c5\u9ed1", 0, 12));
        this.jLabel1.setText(" \u6570\u636e\u6e90\u9009\u62e9\uff1a");
        this.jCheckBox3.setFont(new Font("\u5fae\u8f6f\u96c5\u9ed1", 0, 12));
        this.jCheckBox3.setText("\u7a0b\u5e8f\u6570\u636e\u5e93");
        this.jCheckBox4.setFont(new Font("\u5fae\u8f6f\u96c5\u9ed1", 0, 12));
        this.jCheckBox4.setText("\u7f51\u7edc\u5b9e\u65f6\u6570\u636e");
        this.jCheckBox5.setFont(new Font("\u5fae\u8f6f\u96c5\u9ed1", 0, 12));
        this.jCheckBox5.setText("\u7528\u6237\u5bfc\u5165\u6570\u636e");
        this.jLabel2.setFont(new Font("\u5fae\u8f6f\u96c5\u9ed1", 0, 12));
        this.jLabel2.setText(" \u53c2\u6570\u503c\u8bbe\u7f6e\uff1a");
        this.jLabel3.setFont(new Font("\u5fae\u8f6f\u96c5\u9ed1", 0, 12));
        this.jLabel3.setText("\u7ebf\u7a0b\u6570\uff1a");
        this.jLabel4.setFont(new Font("\u5fae\u8f6f\u96c5\u9ed1", 0, 12));
        this.jLabel4.setText("最大响应时间(毫秒)：");
        this.jTextField1.setText("2000");
        jLabel5.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jLabel5.setText("By eara");
        jToggleButton1.setFont(new java.awt.Font("微软雅黑", 0, 10)); // NOI18N
        jToggleButton1.setIcon(lock);
        jToggleButton1.setEnabled(false);
        jCheckBox1.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jCheckBox1.setText("检测地区信息");
        final GroupLayout jPanel1Layout = new GroupLayout(this.jPanel1);
        this.jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jProgressBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel1)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jCheckBox3))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel2)
                                    .addGap(3, 3, 3)
                                    .addComponent(jLabel3)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGap(6, 6, 6)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel4)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jCheckBox4)
                                    .addGap(18, 18, 18)
                                    .addComponent(jCheckBox5)))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jCheckBox1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(jCheckBox3)
                        .addComponent(jCheckBox4)
                        .addComponent(jCheckBox5)
                        .addComponent(jCheckBox1))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(6, 6, 6))
            );
        final GroupLayout jPanel2Layout = new GroupLayout(this.jPanel2);
        this.jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 0, 32767));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 294, 32767));
        MainFrame.jTextArea1.setEditable(false);
        MainFrame.jTextArea1.setColumns(20);
        MainFrame.jTextArea1.setFont(new Font("\u5fae\u8f6f\u96c5\u9ed1", 0, 15));
        MainFrame.jTextArea1.setRows(5);
        MainFrame.jTextArea1.setText(Data.START_TEXT);
        MainFrame.jTextArea1.getDocument().addDocumentListener(new DocumentListener() {
            @Override
            public void changedUpdate(final DocumentEvent e) {
            }
            
            @Override
            public void insertUpdate(final DocumentEvent e) {
            	if(jTextArea1.getText().length() >= 427 && scollShowFlag){
            		jToggleButton1.setEnabled(true);
            		scollShowFlag = false;
            	}
            	if(!jToggleButton1.isSelected()) MainFrame.jTextArea1.setCaretPosition(MainFrame.jTextArea1.getText().length());
            }
            
            @Override
            public void removeUpdate(final DocumentEvent e) {
            }
        });
        this.jScrollPane1.setViewportView(MainFrame.jTextArea1);
        this.jMenu1.setText("\u9009\u9879");
        MainFrame.jMenuItem1.setAccelerator(KeyStroke.getKeyStroke(82, 2));
        MainFrame.jMenuItem1.setIcon(new ImageIcon(this.getClass().getResource("/images/in.png")));
        MainFrame.jMenuItem1.setText("\u5bfc\u5165");
        MainFrame.jMenuItem1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent evt) {
                MainFrame.this.jMenuItem1ActionPerformed(evt);
            }
        });
        this.jMenu1.add(MainFrame.jMenuItem1);
        MainFrame.jMenuItem2.setAccelerator(KeyStroke.getKeyStroke(68, 2));
        MainFrame.jMenuItem2.setIcon(new ImageIcon(this.getClass().getResource("/images/out.png")));
        MainFrame.jMenuItem2.setText("\u5bfc\u51fa");
        MainFrame.jMenuItem2.setEnabled(false);
        MainFrame.jMenuItem2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent evt) {
                MainFrame.this.jMenuItem2ActionPerformed(evt);
            }
        });
        this.jMenu1.add(MainFrame.jMenuItem2);
        jMenuItem6.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/proxy.png"))); // NOI18N
        jMenuItem6.setText("使用结果设置代理");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenuItem6.setEnabled(false);
        jMenu1.add(jMenuItem6);
        this.jMenu1.add(this.jSeparator1);
        this.jMenuItem3.setIcon(new ImageIcon(this.getClass().getResource("/images/exit.png")));
        this.jMenuItem3.setText("\u9000\u51fa");
        this.jMenuItem3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent evt) {
                MainFrame.this.jMenuItem3ActionPerformed(evt);
            }
        });
        this.jMenu1.add(this.jMenuItem3);
        this.jMenuBar1.add(this.jMenu1);
        this.jMenu2.setText("\u5173\u4e8e");
        this.jMenuItem4.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, 2));
        this.jMenuItem4.setIcon(new ImageIcon(this.getClass().getResource("/images/help.png")));
        this.jMenuItem4.setText("\u5e2e\u52a9");
        this.jMenuItem4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent evt) {
                MainFrame.this.jMenuItem4ActionPerformed(evt);
            }
        });
        this.jMenu2.add(this.jMenuItem4);
        this.jMenuItem5.setIcon(new ImageIcon(this.getClass().getResource("/images/info.png")));
        this.jMenuItem5.setText("\u66f4\u65b0");
        this.jMenuItem5.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent evt) {
                MainFrame.this.jMenuItem5ActionPerformed(evt);
            }
        });
        this.jMenu2.add(this.jMenuItem5);
        this.jMenuBar1.add(this.jMenu2);
        this.setJMenuBar(this.jMenuBar1);
        final GroupLayout layout = new GroupLayout(this.getContentPane());
        this.getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane1)
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(0, 0, Short.MAX_VALUE)
                            .addComponent(jLabel5)
                            .addGap(196, 196, 196)
                            .addComponent(jToggleButton1)))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addGap(11, 11, 11)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap())
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(2, 2, 2)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel5)
                                .addComponent(jToggleButton1)))))
            );
            this.pack();
    }
    
    private void jButton1ActionPerformed(final ActionEvent evt) {
    	if(this.jTextField1.getText().equals("supper")){
    		supper = true;
    		this.jComboBox1.setModel(new DefaultComboBoxModel<String>(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "25" , "30" , "35" , "40" , "50" , "100(后果自负)"}));
    		MainFrame.jTextArea1.setText("开启超级模式~");
    		jTextField1.setText("2000");
    		return;
    	}
    	threadNum = this.jComboBox1.getSelectedIndex() + 1;
        try {
            ms = Integer.valueOf(this.jTextField1.getText());
            if (ms < 100 || ms > 5000) {
                throw new Exception();
            }
        }
        catch (Exception e) {
            MainFrame.jTextArea1.setText("最大响应时间错误！请输入正确的毫秒数，取值：100-5000");
            return;
        }
        if (!this.jCheckBox3.isSelected() && !this.jCheckBox4.isSelected() && !this.jCheckBox5.isSelected()) {
            MainFrame.jTextArea1.setText("请选择至少一个数据源！");
            return;
        }
        if (MainFrame.buttonFlag) {
        	new TypeFrame().setVisible(true);
        }
        else {
        	MainFrame.jButton1.setEnabled(false);
        	MainFrame.jButton1.setText("正在停止");
            MainFrame.jTextArea1.append("\u6b63\u5728\u505c\u6b62...\n");
            Data.run = false;
//            MainFrame.jProgressBar1.setValue(0);
//            MainFrame.jProgressBar1.setString("");
        }
    }
    
    private void jMenuItem3ActionPerformed(final ActionEvent evt) {
    	if(ProxyFrame.running) Proxy.removeProxy();
        System.exit(0);
    }
    
    private void jMenuItem4ActionPerformed(final ActionEvent evt) {
        final HelpFrame hf = new HelpFrame();
        hf.setVisible(true);
    }
    
    private void jMenuItem2ActionPerformed(final ActionEvent evt) {
        (MainFrame.of = new OutFrame()).setVisible(true);
    }
    
    private void jMenuItem1ActionPerformed(final ActionEvent evt) {
    	inFlag = false;
        (this.jFileChooser1 = new JFileChooser()).setFileSelectionMode(0);
        final int returnVal = this.jFileChooser1.showOpenDialog(this.jFileChooser1);
        File file = null;
        if (returnVal == 0) {
            file = this.jFileChooser1.getSelectedFile();
            if (file == null) {
                JOptionPane.showMessageDialog(this, "\u8bf7\u9009\u62e9\u8981\u5bfc\u5165\u7684\u6587\u4ef6\uff01", "\u5bfc\u5165\u4fe1\u606f", 1);
            }
            else {
                final LoadingFrame lf = new LoadingFrame("\u6b63\u5728\u5bfc\u5165\uff0c\u8bf7\u7a0d\u540e\u3002\u3002\u3002");
                lf.addWindowListener(new WindowAdapter() {
                    @Override
                    public void windowClosing(final WindowEvent e) {
                        MainFrame.inFlag = true;
                        super.windowClosing(e);
                    }
                });
                lf.setVisible(true);
                new Thread(new DataUtil(5, file, lf)).start();
            }
        }
    }
    
    private void jMenuItem5ActionPerformed(final ActionEvent evt) {
        final UpdateFrame uf = new UpdateFrame();
        uf.setVisible(true);
    }
    
    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {                                           
    	ProxyFrame pf = new ProxyFrame();
    	pf.setVisible(true);
    	jButton1.setEnabled(false);
    	jMenuItem6.setEnabled(false);
    } 
    
    public static void main(final String[] args) {
        try {
            for (final UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        }
        catch (ClassNotFoundException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (InstantiationException ex2) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex2);
        }
        catch (IllegalAccessException ex3) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex3);
        }
        catch (UnsupportedLookAndFeelException ex4) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex4);
        }
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }
    
    static {
        MainFrame.inFlag = false;
        MainFrame.buttonFlag = true;
    }
    
    class ProgressThread implements Runnable
    {
        @Override
        public void run() {
        	MainFrame.jProgressBar1.setValue(0);
        	MainFrame.jProgressBar1.setString("");
            while (Data.flag > 0) {
                try {
                    Thread.sleep(500L);
                }
                catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            int total = Data.ips.size();
            Data.total = total;
            MainFrame.jProgressBar1.setMaximum(total);
            while (!Data.ips.isEmpty() && Data.run) {
                int checkNum = Data.checkedNum;
                MainFrame.jProgressBar1.setValue(checkNum);
                double pre = (double)checkNum / (double)total * 100.0;
                DecimalFormat df = new DecimalFormat("#0.00");
                MainFrame.jProgressBar1.setString(df.format(pre) + "%("+Data.checkedNum+"/"+Data.total+")");
                try {
                    Thread.sleep(500L);
                }
                catch (InterruptedException e2) {
                    e2.printStackTrace();
                }
            }
        }
    }

    class TypeFrame extends javax.swing.JFrame {

        public TypeFrame() {
            initComponents();
        }

        private void initComponents() {

            jLabel1 = new javax.swing.JLabel();
            jComboBox1 = new javax.swing.JComboBox<>();
            jButton1 = new javax.swing.JButton();
            setBounds(Toolkit.getDefaultToolkit().getScreenSize().width / 2 - 100, Toolkit.getDefaultToolkit().getScreenSize().height / 2 - 100, 522, 448);
            Toolkit tk = Toolkit.getDefaultToolkit();
            Image imgae = tk.createImage(this.getClass().getResource("/images/logo.png"));
            setIconImage(imgae);
            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            setTitle("类型选择");
            setAlwaysOnTop(true);
            setResizable(false);

            jLabel1.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
            jLabel1.setText("类型：");

            jComboBox1.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
            jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "HTTP", "HTTPS", "HTTP/HTTPS" }));

            jButton1.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
            jButton1.setText("开始");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });

            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                    .addContainerGap()
                                    .addComponent(jLabel1)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jButton1)
                                    .addContainerGap())
            );
            layout.setVerticalGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                    .addGap(23, 23, 23)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel1)
                                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jButton1))
                                    .addContainerGap(26, Short.MAX_VALUE))
            );

            pack();
        }// </editor-fold>

        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            Data.proxyType = jComboBox1.getSelectedIndex();
            this.dispose();
            Data.init();
            MainFrame.jMenuItem2.setEnabled(false);
            MainFrame.jMenuItem6.setEnabled(false);
            MainFrame.buttonFlag = false;
            MainFrame.jButton1.setText("\u505c\u6b62");
            MainFrame.jMenuItem1.setEnabled(false);
            MainFrame.jTextArea1.setText("\u5f00\u59cb\u6267\u884c...\n");
            if (jCheckBox3.isSelected()) {
                MainFrame.jTextArea1.append("开始读取程序数据源...\n");
                new Thread(new DataUtil(1)).start();
                ++Data.flag;
            }
            if (jCheckBox5.isSelected()) {
                MainFrame.jTextArea1.append("开始读取用户数据源...\n");
                new Thread(new DataUtil(2)).start();
                ++Data.flag;
            }
            if (jCheckBox4.isSelected()) {
                MainFrame.jTextArea1.append("开始读取网络数据源...\n");
                new Thread(new DataUtil(3)).start();
                ++Data.flag;
            }
            new Thread(new DataUtil(4, threadNum, ms, jCheckBox1.isSelected())).start();
            new Thread(new ProgressThread()).start();
        }

        private javax.swing.JButton jButton1;
        private javax.swing.JComboBox<String> jComboBox1;
        private javax.swing.JLabel jLabel1;
    }
}
